#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(push_constant) uniform PushConstants {
    mat4 projection;
    mat4 modelview;
} pc;

layout(constant_id = 0) const uint numBaseTextures = 1;

//layout(set = 0, binding = 0) uniform sampler2D heightField[numBaseTextures];

layout(set = 1, binding = 0) uniform TileSettings {
	ivec3 tileIndex;
} tileSettings;

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec3 ijk;
layout(location = 3) in vec4 inTexCoord;

layout (location = 0) out vec4 outUV;
layout (location = 1) out float outLodBias;
layout (location = 2) out vec3 outNormal;
layout (location = 3) out vec3 outViewVec;
layout (location = 4) out vec3 outLightVec;
layout (location = 5) out vec3 outIJK;

out gl_PerVertex 
{
    vec4 gl_Position;   
};

void main() 
{
	outUV = inTexCoord;
	vec3 worldPos = vec3(pc.modelview * vec4(inPosition, 1.0));

	gl_Position = (pc.projection * pc.modelview) * vec4(inPosition.xyz,1.0);

	outNormal = mat3(inverse(transpose(pc.modelview))) * inNormal;
	vec3  lightPos = vec3(1,1,1);
	vec3  lPos = mat3(pc.modelview) * lightPos.xyz;
    outLightVec = lPos - worldPos.xyz;
    outViewVec = worldPos.xyz;	
    outIJK = ijk;
}